﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;
using TopMachine.Topping.Dto;

namespace Topping.Core.Proxy.Local.Client
{
    public class ThreadMessager
    {

        public bool isLoading = false;
        public bool isSuspended = false;

        public static ThreadMessager Instance;
       
        static System.Threading.Thread thread;

        public System.Threading.Timer timer = null;

        private Queue<MessageDto> Messages = new Queue<MessageDto>(); 

        public static void InitializeInstance()
        {
            /*if (Instance != null && Instance.timer != null)
            {
                Instance.timer.Dispose(); 
            }

            Instance = new ThreadMessager();
            thread = new System.Threading.Thread(Instance.LoadTimer);
            thread.Start();
            Instance.LoadTimer(); */
        }

        public void StopTimer()
        {
            stop = true;
        }

        public void LoadTimer()
        {
           /* timer = new System.Threading.Timer(TimerRoomsProc);
            timer.Change(5000, 0);*/

        }

        private bool stop = false;
        private bool suspended = false;
        private static object syncRoot = new object();

        private void TimerRoomsProc(object state)
        {
            if (!stop)
            {
                try
                {
                    if (!suspended)
                    {
                       MessageProxy.Proxy.GetMessages();
                    }
                }
                finally
                {
                    ;
                }

                if (!stop) timer.Change(5000, 0);
            }
            else
            {
                timer.Dispose();
            }
        }



        public void Suspend()
        {
            suspended = true;

        }

        public void Resume()
        {
            suspended = false;
        }
    }
}
